﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pin : MonoBehaviour {

    private bool isReady = false;
    private bool isGo = false;
    public float speed = 5;
    private Transform circle;

    private Vector3 targetCirclePoint;
    private Transform startPoint;

	// Use this for initialization
	void Start () {
        startPoint = GameObject.Find("StartPoint").transform;
        circle = GameObject.FindGameObjectWithTag("circle").transform;
        targetCirclePoint = circle.position;
        targetCirclePoint.y -= 1.5f;
	}
	
	// Update is called once per frame
	void Update () {

        if (isGo == false)
        {
            if (isReady == false)
            {
                transform.position = Vector3.MoveTowards(transform.position, startPoint.position, speed * Time.deltaTime);
                if (Vector3.Distance(transform.position, startPoint.position) < 0.05f) isReady = true;
            }
        }
        else
        {
            transform.position = Vector3.MoveTowards(transform.position, targetCirclePoint, speed * Time.deltaTime);
            if (Vector3.Distance(transform.position, targetCirclePoint) < 0.05f)
            {
                transform.position = targetCirclePoint;
                transform.parent = circle;
                isGo = false;
            }
        }
		
	}

    public void StartFly()
    {
        isReady = true;
        isGo = true;
    }
}
